home *** CD-ROM | disk | FTP | other *** search
/ InterCD 2000 September / september_2000.iso / intercd / root / ^Linux / WindowMaker / WPrefs.app / Themes.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-06-04  |  5.8 KB  |  262 lines

  1. /* Themes.c- Theme stuff
  2.  * 
  3.  *  WPrefs - Window Maker Preferences Program
  4.  * 
  5.  *  Copyright (c) 1998 Alfredo K. Kojima
  6.  * 
  7.  *  This program is free software; you can redistribute it and/or modify
  8.  *  it under the terms of the GNU General Public License as published by
  9.  *  the Free Software Foundation; either version 2 of the License, or
  10.  *  (at your option) any later version.
  11.  *
  12.  *  This program is distributed in the hope that it will be useful,
  13.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.  *  GNU General Public License for more details.
  16.  *
  17.  *  You should have received a copy of the GNU General Public License
  18.  *  along with this program; if not, write to the Free Software
  19.  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 
  20.  *  USA.
  21.  */
  22.  
  23.  
  24. #include "WPrefs.h"
  25.  
  26. #include <unistd.h>
  27.  
  28. typedef struct _Panel {
  29.     WMFrame *frame;
  30.  
  31.     char *sectionName;
  32.  
  33.     CallbackRec callbacks;
  34.     
  35.     WMWindow *win;
  36.  
  37.     WMButton *saveB;
  38.     WMList *list;
  39.     WMButton *loadB;
  40.     WMButton *instB;
  41.     
  42.     WMFrame *totF;
  43.     WMButton *totB;
  44.     WMLabel *totL;
  45.     
  46.     WMFrame *botF;
  47.     WMButton *botB;
  48.     WMLabel *botL;
  49.  
  50.     pid_t tilePID;
  51.     pid_t barPID;
  52. } _Panel;
  53.  
  54.  
  55.  
  56. #define ICON_FILE    "theme"
  57.  
  58.  
  59. static void
  60. showData(_Panel *panel)
  61. {
  62.  
  63. }
  64.  
  65.  
  66. static void
  67. finishedTileDownload(void *data)
  68. {
  69.     _Panel *panel = (_Panel*)data;
  70.  
  71.     WMSetButtonText(panel->totB, _("Set"));
  72.     panel->tilePID = 0;
  73. }
  74.  
  75.  
  76.  
  77. static void
  78. finishedBarDownload(void *data)
  79. {
  80.     _Panel *panel = (_Panel*)data;
  81.  
  82.     WMSetButtonText(panel->botB, _("Set"));
  83.     panel->barPID = 0;
  84. }
  85.  
  86.  
  87. static pid_t
  88. downloadFile(WMScreen *scr, _Panel *panel, char *file)
  89. {
  90.     pid_t pid;
  91.     
  92.     pid = fork();
  93.     if (pid < 0) {
  94.     wsyserror("could not fork() process");
  95.  
  96.     WMRunAlertPanel(scr, panel->win, _("Error"), 
  97.             "Could not start download. fork() failed",
  98.             _("OK"), NULL, NULL);
  99.     return -1;
  100.     }
  101.     if (pid != 0) {
  102.     return pid;
  103.     }
  104.  
  105.     close(ConnectionNumber(WMScreenDisplay(scr)));
  106.  
  107.     
  108.  
  109.     exit(1);
  110. }
  111.  
  112.  
  113. static void
  114. downloadCallback(WMWidget *w, void *data)
  115. {
  116.     _Panel *panel = (_Panel*)data;
  117.     pid_t newPid;
  118.     WMButton *button = (WMButton*)w;
  119.     pid_t *pid;
  120.  
  121.     if (button == panel->totB) {
  122.     pid = &panel->tilePID;
  123.     } else {
  124.     pid = &panel->barPID;
  125.     }
  126.     
  127.     if (*pid == 0) {
  128.     newPid = downloadFile(WMWidgetScreen(w), panel, NULL);
  129.     if (newPid < 0) {
  130.         return;
  131.     }
  132.     WMSetButtonText(button, _("Stop"));
  133.  
  134.     if (button == panel->totB) {
  135.         AddDeadChildHandler(newPid, finishedTileDownload, data);
  136.     } else {
  137.         AddDeadChildHandler(newPid, finishedBarDownload, data);
  138.     }
  139.     *pid = newPid;
  140.     } else {
  141.     *pid = 0;
  142.  
  143.     WMSetButtonText(button, _("Download"));
  144.     }
  145. }
  146.  
  147.  
  148.  
  149. static void
  150. updateThemeList(_Panel *panel)
  151. {
  152.     WMClearList(panel->list);
  153.  
  154.     
  155.     
  156. }
  157.  
  158.  
  159.  
  160. static void
  161. createPanel(Panel *p)
  162. {
  163.     _Panel *panel = (_Panel*)p;
  164.  
  165.     panel->frame = WMCreateFrame(panel->win);
  166.     WMResizeWidget(panel->frame, FRAME_WIDTH, FRAME_HEIGHT);
  167.     WMMoveWidget(panel->frame, FRAME_LEFT, FRAME_TOP);
  168.  
  169.     panel->saveB = WMCreateCommandButton(panel->frame);
  170.     WMResizeWidget(panel->saveB, 154, 24);
  171.     WMMoveWidget(panel->saveB, 15, 10);
  172.     WMSetButtonText(panel->saveB, _("Save Current Theme"));
  173.  
  174.     panel->list = WMCreateList(panel->frame);
  175.     WMResizeWidget(panel->list, 154, 150);
  176.     WMMoveWidget(panel->list, 15, 40);
  177.  
  178.     panel->loadB = WMCreateCommandButton(panel->frame);
  179.     WMResizeWidget(panel->loadB, 74, 24);
  180.     WMMoveWidget(panel->loadB, 15, 200);
  181.     WMSetButtonText(panel->loadB, _("Load"));
  182.  
  183.     panel->instB = WMCreateCommandButton(panel->frame);
  184.     WMResizeWidget(panel->instB, 74, 24);
  185.     WMMoveWidget(panel->instB, 95, 200);
  186.     WMSetButtonText(panel->instB, _("Install"));
  187.  
  188.     
  189.     /**************** Tile of the day ****************/
  190.     
  191.     panel->totF = WMCreateFrame(panel->frame);
  192.     WMResizeWidget(panel->totF, 210, 105);
  193.     WMMoveWidget(panel->totF, 240, 10);
  194.     WMSetFrameTitle(panel->totF, _("Tile of The Day"));
  195.  
  196.     panel->totL = WMCreateLabel(panel->totF);
  197.     WMResizeWidget(panel->totL, 67, 67);
  198.     WMMoveWidget(panel->totL, 25, 25);
  199.     WMSetLabelRelief(panel->totL, WRSunken);
  200.  
  201.     panel->totB = WMCreateCommandButton(panel->totF);
  202.     WMResizeWidget(panel->totB, 86, 24);
  203.     WMMoveWidget(panel->totB, 105, 45);
  204.     WMSetButtonText(panel->totB, _("Download"));
  205.     WMSetButtonAction(panel->totB, downloadCallback, panel);
  206.  
  207.     WMMapSubwidgets(panel->totF);
  208.     
  209.     /**************** Bar of the day ****************/
  210.  
  211.     panel->botF = WMCreateFrame(panel->frame);
  212.     WMResizeWidget(panel->botF, 315, 95);
  213.     WMMoveWidget(panel->botF, 190, 125);
  214.     WMSetFrameTitle(panel->botF, _("Bar of The Day"));
  215.  
  216.     panel->botL = WMCreateLabel(panel->botF);
  217.     WMResizeWidget(panel->botL, 285, 32);
  218.     WMMoveWidget(panel->botL, 15, 20);
  219.     WMSetLabelRelief(panel->botL, WRSunken);
  220.  
  221.     panel->botB = WMCreateCommandButton(panel->botF);
  222.     WMResizeWidget(panel->botB, 86, 24);
  223.     WMMoveWidget(panel->botB, 110, 60);
  224.     WMSetButtonText(panel->botB, _("Download"));
  225.     WMSetButtonAction(panel->botB, downloadCallback, panel);
  226.  
  227.     WMMapSubwidgets(panel->botF);
  228.  
  229.     WMRealizeWidget(panel->frame);
  230.     WMMapSubwidgets(panel->frame);
  231.     
  232.     showData(panel);
  233. }
  234.  
  235.  
  236. static void
  237. storeData(_Panel *panel)
  238. {
  239. }
  240.  
  241.  
  242.  
  243. Panel*
  244. InitThemes(WMScreen *scr, WMWindow *win)
  245. {
  246.     _Panel *panel;
  247.  
  248.     panel = wmalloc(sizeof(_Panel));
  249.     memset(panel, 0, sizeof(_Panel));
  250.  
  251.     panel->sectionName = _("Themes");
  252.     
  253.     panel->win = win;
  254.     
  255.     panel->callbacks.createWidgets = createPanel;
  256.     panel->callbacks.updateDomain = storeData;
  257.  
  258.     AddSection(panel, ICON_FILE);
  259.  
  260.     return panel;
  261. }
  262.